package com.avocado.base.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.avocado.persistence.repository.BaseRepository;
import com.avocado.base.entity.ResourcesRole;
import com.avocado.base.entity.ResourcesRoleId;
import com.avocado.base.enums.ResourcesType;

public interface ResourcesRoleRepository extends BaseRepository<ResourcesRole, ResourcesRoleId> {
	
	/**
	 * 按ID统计
	 * @param id
	 * @return
	 */
	@Query("select count(1) from ResourcesRole where id=?1")
	Long getCountById(ResourcesRoleId id);
	
	
	@Query("from ResourcesRole t where t.role.id=?1 and t.resources.type=?2")
	List<ResourcesRole> findAll(Long roleId, ResourcesType resourcesType);
	
	@Modifying
	@Query("delete from ResourcesRole t where t.role.id=?1")
	Integer deleteAllByRoleId(Long roleId);
	
	@Modifying
	@Query("delete from ResourcesRole t where t.id=?1")
	Integer deleteAllById(ResourcesRoleId id);

}
